package com.zhang.modules.mianShi.controller;

import com.zhang.common.web.respWrapper.Res;
import com.zhang.modules.api.annotation.ApiPermission;
import com.zhang.modules.mianShi.entity.Equipment;
import com.zhang.modules.mianShi.entity.MachineGroup;
import com.zhang.modules.mianShi.entity.Region;
import com.zhang.modules.mianShi.entity.cmd.equipment.EquipmentAddCmd;
import com.zhang.modules.mianShi.entity.cmd.equipment.EquipmentEditCmd;
import com.zhang.modules.mianShi.entity.cmd.equipment.EquipmentPageCmd;
import com.zhang.modules.mianShi.entity.cmd.machine.MachineAddCmd;
import com.zhang.modules.mianShi.entity.cmd.machine.MachineEditCmd;
import com.zhang.modules.mianShi.entity.cmd.region.RegionPageCmd;
import com.zhang.modules.mianShi.service.IEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;


@RestController
@Api(tags = "设备管理")
@RequestMapping("/api/equipment")
@ApiPermission("app:equipment:*")
public class EquipmentController {

    private IEquipmentService service;

    public EquipmentController(IEquipmentService service) {
        this.service = service;
    }

    @ApiOperation("设备添加")
    @ApiPermission("app:equipment:add")
    @PostMapping("/add")
    public Res add(@RequestBody @Valid EquipmentAddCmd addCmd){
        service.save(addCmd, Equipment::new);
        return Res.ok("添加成功");
    }

    @ApiOperation("设备编辑")
    @ApiPermission("app:equipment:edit")
    @PostMapping("/edit")
    public Res edit(@RequestBody @Valid EquipmentEditCmd editCmd){
        service.update(editCmd);
        return Res.ok("更新成功");
    }

    @ApiOperation("设备删除")
    @ApiPermission("app:equipment:delete")
    @GetMapping("/delete")
    public Res delete(@Valid @NotBlank(message = "id不能为空") String id){
        service.deleteLogic(id);
        return Res.ok("删除成功");
    }


    @ApiOperation("设备列表")
    @ApiPermission("app:equipment:page")
    @GetMapping("/page")
    public Res page(@Valid  EquipmentPageCmd pageCmd){
        Page<Equipment> page = service.page(pageCmd);
        return Res.ok(page);
    }




}
